package me.zhengjie.modules.system.service.impl;

import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.mnt.util.CodeUitl;
import me.zhengjie.modules.system.domain.Contract;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.domain.UserInfo;
import me.zhengjie.modules.system.domain.UserInsuranceInfo;
import me.zhengjie.modules.system.repository.ContractRepository;
import me.zhengjie.modules.system.repository.UserInfoRepository;
import me.zhengjie.modules.system.repository.UserInsuranceInfoRepository;
import me.zhengjie.modules.system.service.UserInfoService;
import me.zhengjie.utils.DateUtil;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "userInfo")
public class UserInfoServiceImpl implements UserInfoService {

    private final UserInfoRepository userInfoRepository;
    private final ContractRepository contractRepository;
    private final UserInsuranceInfoRepository insuranceInfoRepository;

    @Override
    public List<UserInfo> fandByUserConditionList(String userName, String userType) {
        return userInfoRepository.fandByUserConditionList(userName, userType);
    }

    @Override
    public UserInfo fandByUserCondition(Integer userId) {
        return userInfoRepository.fandByUserCondition(userId);
    }


    @Override
    public UserInfo updateUserInfo(UserInfo userInfo) {
        return userInfoRepository.save(userInfo);
    }

    public Contract selectContractInfo(String userInfoId) {
        return contractRepository.findByUserInfoId(userInfoId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveContractInfo(Contract contract) {
        //修改合同签订状态
        userInfoRepository.updateAuditStatus(contract.getUsersInfoId(), "1");

        //新增合同信息
        contractRepository.save(contract);
    }

    @Override
    public void updateStatus(Integer userId, String userStatus) {
        userInfoRepository.updateStatus(userId, userStatus);
    }
}
